/************************************\
|* unittest1.c                      *|
|* By Danny Burrows                 *|
|* burrowsd@onid.oregonstate.edu    *|
|* CS362 - Spring 2014              *|
|*                                  *|
|* Assignment 3                     *|
|*                                  *|
|* Simple unit tests of the         *|
|* initializeGame function inside   *|
|* dominion.c                       *|
\************************************/

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include "dominion.h"

void checkTest(char *string, int expected, int result)
{
	if (expected == result)
		printf("PASS - %s: expected - %d, result - %d\n", string, expected, result);
	else
		printf("FAIL - %s: expected - %d, result - %d\n", string, expected, result);

	return;
}

void runTests(struct gameState *game)
{
	/* Run unit tests */
	int *k = malloc(sizeof(int) * 10);
	int seed = rand() % (INT_MAX - 1) + 1;
	k = kingdomCards(0,1,2,3,4,5,6,7,8,9); // kindom cards required, if these values change, most of the tests fail
	checkTest("numPlayers", 0, game->numPlayers);
	checkTest("supplyCount[curse]", 0, game->supplyCount[curse]);
	checkTest("supplyCount[estate]", 0, game->supplyCount[estate]);
	checkTest("supplyCount[duchy]", 0, game->supplyCount[duchy]);
	checkTest("supplyCount[province]", 0, game->supplyCount[province]);
	checkTest("supplyCount[cooper]", 0, game->supplyCount[copper]);
	checkTest("supplyCount[silver]", 0, game->supplyCount[silver]);
	checkTest("supplyCount[gold]", 0, game->supplyCount[gold]);
	checkTest("deckCount[0]", 0, game->deckCount[0]);
	checkTest("deckCount[1]", 0, game->deckCount[0]);
	checkTest("outpostPlayed", 0, game->outpostPlayed);
	checkTest("phase", 0, game->phase);
	checkTest("numActions", 0, game->numActions);
	checkTest("numBuys", 0, game->numBuys);
	checkTest("playedCardCount", 0, game->playedCardCount);
	checkTest("whoseTurn", 0, game->whoseTurn);
	printf("-- Initializing game state --\n");
	initializeGame(2, k, seed, game);
	checkTest("numPlayers", 2, game->numPlayers);
	checkTest("supplyCount[curse]", 10, game->supplyCount[curse]);
	checkTest("supplyCount[estate]", 8, game->supplyCount[estate]);
	checkTest("supplyCount[duchy]", 8, game->supplyCount[duchy]);
	checkTest("supplyCount[province]", 8, game->supplyCount[province]);
	checkTest("supplyCount[copper]", 46, game->supplyCount[copper]);
	checkTest("supplyCount[silver]", 40, game->supplyCount[silver]);
	checkTest("supplyCount[gold]", 30, game->supplyCount[gold]);
	checkTest("deckCount[0]", 5, game->deckCount[0]);
	checkTest("deckCount[1]", 5, game->deckCount[0]);
	checkTest("outpostPlayed", 0, game->outpostPlayed);
	checkTest("phase", 0, game->phase);
	checkTest("numActions", 1, game->numActions);
	checkTest("numBuys", 1, game->numBuys);
	checkTest("playedCardCount", 0, game->playedCardCount);
	checkTest("whoseTurn", 0, game->whoseTurn);

	return;
}

int main(int argc, char const *argv[])
{
	struct gameState *game = malloc(sizeof(struct gameState));

	runTests(game);
	free(game);

	return 0;
}